package com.bootdo.common.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bootdo.common.dao.GeneseqDao;
import com.bootdo.common.geneseq.DbSeqFactory;
import com.bootdo.common.geneseq.sequence.Sequence;
import com.bootdo.common.service.GeneseqService;
import com.smart.domain.GeneseqDO;



@Service
public class GeneseqServiceImpl implements GeneseqService {
	@Autowired
	private GeneseqDao geneseqDao;
	
	@Override
	public GeneseqDO get(Long id){
		return geneseqDao.get(id);
	}
	
	@Override
	public List<GeneseqDO> list(Map<String, Object> map){
		return geneseqDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return geneseqDao.count(map);
	}
	
	@Override
	public int save(GeneseqDO geneseq){
		geneseq.setGmtCreate(new Date());
		geneseq.setGmtModified(new Date());

		return geneseqDao.save(geneseq);
	}
	
	@Override
	public int update(GeneseqDO geneseq){
		geneseq.setGmtModified(new Date());
		return geneseqDao.update(geneseq);
	}
	
	@Override
	public int remove(Long id){
		return geneseqDao.remove(id);
	}
	
	@Override
	public int batchRemove(Long[] ids){
		return geneseqDao.batchRemove(ids);
	}

	@Override
	public Long getNextValue(String serviceCode) {
		Sequence sequence = DbSeqFactory.getSequence(serviceCode);
		long nextValue = sequence.nextValue();
		return nextValue;
	}

	@Override
	public Long selectRange(String serviceName) {
		GeneseqDO geneseqDO = geneseqDao.selectRange(serviceName);
		return geneseqDO.getValue();
	}

	@Override
	public int updateRange(Long newValue, Long oldValue, String name) {
		return geneseqDao.updateRange(newValue,oldValue,name,new Date());
	}
	
}
